package cuiyt.offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author cyt
 * @create 2020-05-26 17:53
 */
public class T33 {

    /***
     * 层序遍历 二叉树
     * @param args
     */
    public static void main(String[] args) {

        ans = new ArrayList<>();
    }

    static ArrayList<ArrayList<Integer>> ans;

    static ArrayList<ArrayList<Integer>> Print(TreeNode33 pRoot) {


        return null;
    }

    static void dfs(TreeNode33 node) {
        Queue<TreeNode33> queue = new LinkedList<>();
        ArrayList<Integer> list = new ArrayList<>();
        int row = 1;
        int num = 0;

        queue.add(node);

        while (!queue.isEmpty()) {
            row--;
            TreeNode33 peek = queue.peek();
            list.add(peek.val);
            queue.remove();
            if (peek.left != null) {
                queue.add(peek.left);
                num++;
            }
            if (peek.right != null) {
                queue.add(peek.right);
                num++;
            }

            if (row == 0) {
                ans.add(new ArrayList<>(list));

                list.clear();
                row = num;
                num = 0;
            }
        }
    }
}

class TreeNode33 {
    int val = 0;
    TreeNode33 left = null;
    TreeNode33 right = null;

    public TreeNode33(int val) {
        this.val = val;

    }

}
